using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Dll.DAL;
using Dll.Essences;
using System.Collections;

namespace Price_Guide
{
    public partial class UserCard : Form
    {
        public bool f = false;
        int UserID;
        int type;
        public UserCard()
        {
            InitializeComponent();
            comboBox1.DataSource = UserTypeDAL.GetAllUserType();
            comboBox1.DisplayMember = "name";
            comboBox1.ValueMember = "id";
            type = 1;
            this.Icon = Price_Guide.Properties.Resources.user1;
        }

        public UserCard(int userID)
        {
            InitializeComponent();
            UserID = userID;
            comboBox1.DataSource = UserTypeDAL.GetAllUserType();
            comboBox1.DisplayMember = "name";
            comboBox1.ValueMember = "id";
            Users U = UsersDAL.GetUsersByID(userID);
            Log.Text = U.UserName;
            Pass.Text = U.Password;
            type = 2;
            this.Icon = Price_Guide.Properties.Resources.user1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (Log.Text != "" && type == 1)
            {
                Users user = new Users();
                user.UserName = Log.Text;
                user.Password = Pass.Text;
                user.UserTypeId = Convert.ToInt32(comboBox1.SelectedValue);
                UsersDAL.InsertUsers(user);
                f = true;
                this.Close();
            }

            if (Log.Text != "" && type == 2)
            {
                Users user = new Users();
                user.UserName = Log.Text;
                user.Password = Pass.Text;
                user.UserTypeId = Convert.ToInt32(comboBox1.SelectedValue);
                user.Id = UserID;
                UsersDAL.UpdateUsers(user);
                f = true;
                this.Close();
            }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Log_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
                button1_Click(null, null);
            if(e.KeyValue==27)
                button2_Click(null, null);
        }
    }
}